package com.scsj.supermarket.view.activity.goodmodel;

import android.media.tv.TvContract;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gigamole.navigationtabstrip.NavigationTabStrip;
import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.MainFragmentAdapter;
import com.scsj.supermarket.base.QueryConpouBase;
import com.scsj.supermarket.bean.CoupouRequestBean;
import com.scsj.supermarket.bean.MineCouponBean;
import com.scsj.supermarket.presenter.MineConpouPresenter;
import com.scsj.supermarket.presenter.RegisterPresenter;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.scsj.supermarket.view.fragment.basemodel.BaseFragment;
import com.scsj.supermarket.view.fragment.couponmodel.CouponOverdue;
import com.scsj.supermarket.view.fragment.couponmodel.CouponUnused;
import com.scsj.supermarket.view.fragment.couponmodel.CouponUsed;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import es.dmoral.toasty.Toasty;
import okhttp3.RequestBody;


/**
 * 优惠券
 */
public class CoupouActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout back_ll, detail_ll;
    private TextView toolbar_title;

    private NavigationTabStrip mTopNavigationTabStrip;
    private ViewPager mViewPager;
    private ArrayList<BaseFragment> fragmentList;
    private MainFragmentAdapter mAdpter;

    private String[] title = {"未使用", "已使用", "已过期"};


//    private MineConpouPresenter presenter;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_coupou);

        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {
        back_ll = findViewById(R.id.back_ll);
        detail_ll = findViewById(R.id.detail_ll);
        toolbar_title = findViewById(R.id.toolbar_title);
        intiNavigationBar();
    }

    @Override
    protected void initData() {
        toolbar_title.setText("优惠券");

//        presenter = new MineConpouPresenter(this);

//        CoupouRequestBean.PageInfoBean bean = new CoupouRequestBean.PageInfoBean();
//        bean.setPageNum(1);
//        bean.setPageSize(10);
//        CoupouRequestBean requestBean = new CoupouRequestBean(bean,"0","1234");
//        Gson gson = new Gson();
//        String obj = gson.toJson(requestBean);
//        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj);
//        presenter.deliverData(body);

    }

    @Override
    protected void initListener() {
        back_ll.setOnClickListener(this);
        detail_ll.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back_ll://返回
                finish();
                break;
            default:
                break;
        }
    }


    private void intiNavigationBar() {

        mTopNavigationTabStrip = (NavigationTabStrip) findViewById(R.id.mediator_tab);
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPager.setOffscreenPageLimit(3);

        CouponUnused couponUnused = new CouponUnused();
        CouponUsed couponUsed = new CouponUsed();
        CouponOverdue couponOverdue = new CouponOverdue();


        fragmentList = new ArrayList<>();
        fragmentList.add(couponUnused);
        fragmentList.add(couponUsed);
        fragmentList.add(couponOverdue);

        mAdpter = new MainFragmentAdapter(getSupportFragmentManager(), fragmentList);
        mViewPager.setAdapter(mAdpter);

        mTopNavigationTabStrip.setViewPager(mViewPager, 0);
        mTopNavigationTabStrip.setTitles(title);
        mTopNavigationTabStrip.setStripType(NavigationTabStrip.StripType.LINE);
        mTopNavigationTabStrip.setStripGravity(NavigationTabStrip.StripGravity.BOTTOM);
        mTopNavigationTabStrip.setTabIndex(0, true);

    }

//    @Override
//    public void showSuccessMsg(String s, MineCouponBean mineCouponBean) {
//
//        Toasty.info(this, "状态"+mineCouponBean.getStatusCode()).show();
//
//        Logger.e("我的优惠券获取成功：",mineCouponBean.toString());
//        Logger.e("状态：",mineCouponBean.getStatusCode());
//
//
//
//
//    }
//
//    @Override
//    public void showErrorMsg(String s) {
//        Toasty.info(this, "网络请求错误").show();
//
//    }
}
